-module(ex04).
-export([new/0, destroy/1, write/3, delete/2, read/2, match/2]).

new() ->
    [].

destroy(_) ->
    [].

write(Key, Element, Db) ->
    [{Key, Element}|Db].

delete(Key, Db) ->
    lists:keydelete(Key, 1, Db).

read(Key, Db) ->
    case lists:keyfind(Key, 1, Db) of
	{Key, Element} -> {ok, Element};
	false -> {error, instance}
    end.

match(Element, [{Key, Element} | TailList]) ->
    [Key | match(Element, TailList)];
match(Element, [_ | TailList]) ->
    match(Element, TailList);
match(_Element, []) ->
    [].
